import { reqGetCategoryList, reqGetBannerList, reqFloorList } from "@/api";

//准备 actions 对象：响应组件中用户的动作
const actions = {
    //获取商品列表
    async categoryList({ commit }) {
        let result = await reqGetCategoryList();
        console.log("商品列表数据", result);
        if (result.code == 200) {
            commit("GET_CATEGORY_LIST", result.data);
        }
    },

    //获取轮播图 mock
    async getBannerList({ commit }) {
        let result = await reqGetBannerList();
        console.log("轮播图数据", result);
        if (result.code == 200) {
            commit("GET_BANNER_LIST", result.data);
        }
    },

    //获取楼层数据 mock
    async getFloorList({ commit }) {
        let result = await reqFloorList();
        console.log("楼层数据", result);
        if (result.code == 200) {
            commit("GET_FLOOR_LIST", result.data);
        }
    }
};

//准备 mutations 对象：修改 state 中的数据
const mutations = {
    //获取商品列表
    GET_CATEGORY_LIST(state, categoryList) {
        state.categoryList = categoryList;
    },

    //获取 banner 轮播图
    GET_BANNER_LIST(state, bannerList) {
        state.bannerList = bannerList;
    },

    //获取楼层数据
    GET_FLOOR_LIST(state, floorList) {
        state.floorList = floorList;
    },
};
//准备 state 对象：保存具体的数据
const state = {
    //state中商品分类初始化，数据类型对应接口返回的数据类型
    categoryList: [],

    //轮播图
    bannerList: [],

    //楼层
    floorList: [],
};

//计算属性
const getters = {};

//创建并暴露 store
export default {
    actions,
    mutations,
    getters,
    state
}